


# Developer Workflow Manual — EnCoach Backend & Frontend

## One-Time Setup (Do This Once)

**Step 1 — Clone the repositories**
```bash
git clone https://git.albousalh.com/devops/encoach_backend_new_v2.git
git clone https://git.albousalh.com/devops/encoach_frontend_new_v2.git
```

**Step 2 — Switch to the working branch**
```bash
cd encoach_backend_new_v2
git checkout full_stack_dev

cd ../encoach_frontend_new_v2
git checkout full_stack_dev
```

**Step 3 — Install the `tea` CLI (to open PRs from terminal)**
```bash
# macOS
brew install tea

# Or download directly:
# https://gitea.com/gitea/tea/releases

# Configure it (run once):
tea login add --name encoach --url https://git.albousalh.com --token YOUR_TOKEN
```
> To get your token: log in at `https://git.albousalh.com` → top-right avatar → Settings → Applications → Generate Token.

---

## Every Day — Starting Work

**Step 4 — Always pull the latest before coding**
```bash
git checkout full_stack_dev
git pull origin full_stack_dev
```
> This makes sure you have the latest code before making changes.

---

## Making Changes

**Step 5 — Make your code changes locally**

Work as normal in your editor. No restrictions on what you change.

**Step 6 — If you add a new Python package**, add it to `new_project/requirements.txt`:
```
openai>=1.50
your-new-package>=x.x
```

**Step 7 — If you add a new Odoo addon**, place it under `new_project/custom_addons/your_module/` and make sure:
- The `__manifest__.py` lists **all** modules you reference via `comodel_name=` in its `depends` list.
- Notify Talal — new addons need a one-time manual install on the server (see end of this doc).

---

## Pushing Your Work

**Step 8 — Stage and commit your changes**
```bash
git add .
git commit -m "Short description of what you changed"
```

**Step 9 — Push to your working branch**
```bash
git push origin full_stack_dev
```

**Step 10 — Open a Pull Request** (asks Talal for review/approval)
```bash
tea pr create \
  --repo devops/encoach_backend_new_v2 \
  --head full_stack_dev \
  --base main \
  --title "Brief title of your changes" \
  --description "What you changed and why"
```
> For frontend, replace `encoach_backend_new_v2` with `encoach_frontend_new_v2`.

**Step 11 — Notify Talal** that a PR is waiting for his review.

---

## After Talal Approves & Merges

**Step 12 — Deployment is fully automatic.** You do not need to do anything on the server.

What happens behind the scenes:
1. Talal merges the PR on `https://git.albousalh.com`
2. The server detects the merge to `main`
3. The deploy script pulls the latest code
4. Docker rebuilds the image (if `Dockerfile` or `requirements.txt` changed — takes ~10–15 min; otherwise ~1 min)
5. The container restarts with the new code

**Step 13 — Verify it worked** by checking the live URL:
- Frontend: `http://5.189.151.117:3000`
- Backend API: `http://5.189.151.117:8069/api/login`

---

## Checking Logs If Something Goes Wrong

SSH into the server (ask Talal for credentials) and run:
```bash
# Backend logs
docker logs backend-v2-odoo --tail 50

# Frontend logs
docker logs encoach-frontend --tail 50
```

---

## Special Case: Adding a New Odoo Addon

New addons need a **one-time manual install** on the server (the database doesn't know about them yet). Tell Talal and he will run:
```bash
ssh root@5.189.151.117
docker stop backend-v2-odoo
docker run --rm \
  --network backend-v2_default \
  -v /opt/encoach/backend-v2/odoo-docker.conf:/etc/odoo/odoo.conf:ro \
  -v /opt/encoach/backend-v2/new_project/custom_addons:/mnt/custom_addons:ro \
  -v /opt/encoach/backend-v2/new_project/enterprise-19:/mnt/enterprise:ro \
  -v /opt/encoach/backend-v2/new_project/openeducat_erp-19.0:/mnt/openeducat:ro \
  -v odoo-web-data:/var/lib/odoo \
  encoach-backend:latest \
  odoo -c /etc/odoo/odoo.conf -d encoach_v2 -i your_new_module --stop-after-init
docker start backend-v2-odoo
```
> After the first install, all future deploys update it automatically.

---

## Quick Reference

| Action | Command |
|---|---|
| Pull latest | `git pull origin full_stack_dev` |
| Commit | `git add . && git commit -m "message"` |
| Push | `git push origin full_stack_dev` |
| Open PR (backend) | `tea pr create --repo devops/encoach_backend_new_v2 --head full_stack_dev --base main --title "..."` |
| Open PR (frontend) | `tea pr create --repo devops/encoach_frontend_new_v2 --head full_stack_dev --base main --title "..."` |
| View logs (backend) | `docker logs backend-v2-odoo --tail 50` |
| View logs (frontend) | `docker logs encoach-frontend --tail 50` |